package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult queryAllNursingLevel() {
        List<NursingLevelVo> list = nursingLevelService.queryAllNursingLevel();
        return success(list);
    }

    /**
     * 新增护理等级
     */
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult addNursingLevel(
            @ApiParam(value = "护理等级数据传输对象", required = true)
            @RequestBody NursingLevelDto nursingLevelDto) {
        logger.info("新增护理等级,请求参数：{}", nursingLevelDto);
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return success();
    }

    /**
     * 条件分页查询护理等级
     */
    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> PageQuery(
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "状态：0-禁用, 1-启用") Integer status
    ) {
        logger.info("分页查询护理等级列表，请求参数 pageNum={}, pageSize={},name={}, status={}",
                pageNum, pageSize, name, status);

        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.PageQuery(pageNum, pageSize, name, status);

        return success(pageResponse);
    }

    /**
     * 根据id查询护理等级
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable("id") Integer id) {
        logger.info("根据ID查询护理等级,请求参数：{}", id);

        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);

        return success(nursingLevelVo);
    }

    /**
     * 修改护理等级
     */
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        logger.info("修改护理等级,请求参数：{}", nursingLevelDto);

        nursingLevelService.updateNursingLevel(nursingLevelDto);

        return success();
    }

    /**
     * 删除护理等级
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable("id") Integer id) {
        logger.info("删除护理等级,请求参数：{}", id);

        nursingLevelService.deleteNursingLevel(id);
        return success();
    }

    /**
     * 护理等级启用或禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("护理等级启用或禁用")
    public ResponseResult EnableOrDisable(
            @ApiParam(value = "id") @PathVariable("id") Integer id,
            @ApiParam(value = "状态") @PathVariable("status") Integer status)
    {
        logger.info("启用或禁用,请求参数：{},{}",id,status);

        boolean result = nursingLevelService.enableOrDisable(id, status);

        if (result) {
            return success("状态更改成功");
        } else {
            return error("状态更改失败，护理等级不存在或状态无效");
        }
    }
}
